<?php
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
require '../com.swiss.mooh.service/MenuServiceImpl.php';
require '../com.swiss.mooh.dao.impl/MenuDaoImpl.php';
require '../com.swiss.mooh.model/Menu.php';

$dispatcher = new MenuDaoImpl();
$menuService = new MenuServiceImpl($dispatcher);

switch ($_POST['type']) {
    case 0:
        $menuTO = new Menu();
        $menuTO->setMenuName($_POST['menuName']);
        $menuTO->setMenuCreatedDateTime(date('Y-m-d h:i:s', time()));
        $menuTO->setMenuID(uniqid());
        $menuTO->setMenuLevel(0);
        $result = $menuService->createNewMenu($menuTO);
        if ($result == 200) {
            $menu_all = $menuService->getAllMenu();
            for ($i = 0; $i < $menu_all->Size(); $i++) {
                ?>
                <a href="#" class="list-group-item">
                    <span class="badge" onclick="editMainMenu('<?= $menu_all->GetObj($i)->getMenuID(); ?>', '<?= $menu_all->GetObj($i)->getMenuName(); ?>')"><i class="fa fa-edit"></i></span>
                    <span class="badge" onclick=deleteMainMenu('<?= $menu_all->GetObj($i)->getMenuID(); ?>')><i class="fa fa-trash"></i></span>
                    <span onclick="getMenuLevelOne('<?= $menu_all->GetObj($i)->getMenuID(); ?>')"><i class="fa fa-fw fa-calendar"></i> <?= $menu_all->GetObj($i)->getMenuName(); ?></span>
                </a>
                <?php
            }
        }
        break;
    case 1:
        $result = $menuService->deleteMenu($_POST['menuID']);
        if ($result == 200) {
            $menu_all = $menuService->getAllMenu();
            for ($i = 0; $i < $menu_all->Size(); $i++) {
                ?>
                <a href="#" class="list-group-item">
                    <span class="badge" onclick="editMainMenu('<?= $menu_all->GetObj($i)->getMenuID(); ?>', '<?= $menu_all->GetObj($i)->getMenuName(); ?>')"><i class="fa fa-edit"></i></span>
                    <span class="badge" onclick=deleteMainMenu('<?= $menu_all->GetObj($i)->getMenuID(); ?>')><i class="fa fa-trash"></i></span>
                    <span onclick="getMenuLevelOne('<?= $menu_all->GetObj($i)->getMenuID(); ?>')"><i class="fa fa-fw fa-calendar"></i> <?= $menu_all->GetObj($i)->getMenuName(); ?></span>
                </a>
                <?php
            }
        }
        break;
    case 2:
        $menuTO = new Menu();
        $menuTO->setMenuID($_POST['menuID']);
        $menuTO->setMenuName($_POST['newMenuname']);
        $result = $menuService->updateMenu($menuTO);
        if ($result == 200) {
            $menu_all = $menuService->getAllMenu();
            for ($i = 0; $i < $menu_all->Size(); $i++) {
                ?>
                <a href="#" class="list-group-item">
                    <span class="badge" onclick="editMainMenu('<?= $menu_all->GetObj($i)->getMenuID(); ?>', '<?= $menu_all->GetObj($i)->getMenuName(); ?>')"><i class="fa fa-edit"></i></span>
                    <span class="badge" onclick=deleteMainMenu('<?= $menu_all->GetObj($i)->getMenuID(); ?>')><i class="fa fa-trash"></i></span>
                    <span onclick="getMenuLevelOne('<?= $menu_all->GetObj($i)->getMenuID(); ?>')"><i class="fa fa-fw fa-calendar"></i> <?= $menu_all->GetObj($i)->getMenuName(); ?></span>
                </a>
                <?php
            }
        }
        break;
    case 3:
        $menuTO = new Menu();
        $menuTO->setMenuID(uniqid());
        $menuTO->setMenuCreatedDateTime(date('Y-m-d h:i:s', time()));
        $menuTO->setMenuLevel(1);
        $menuTO->setRefID($_POST['ref_id']);
        $menuTO->setMenuName($_POST['menuName']);
        $result = $menuService->createNewMenuLevel1($menuTO);
        if ($result == 200) {
            $menu_all = $menuService->getAllMenuLevelOneByMainMenuID($_POST['ref_id']);
            for ($i = 0; $i < $menu_all->Size(); $i++) {
                ?>
                <a href="#" class="list-group-item">
                    <span class="badge"><i class="fa fa-code"></i></span>
                    <span class="badge" onclick="editMenuLevel1('<?= $menu_all->GetObj($i)->getMenuID(); ?>', '<?= $menu_all->GetObj($i)->getMenuName(); ?>', '<?= $menu_all->GetObj($i)->getRefID(); ?>')"><i class="fa fa-edit"></i></span>
                    <span class="badge" onclick=deleteMenuLevel1('<?= $menu_all->GetObj($i)->getMenuID(); ?>','<?= $menu_all->GetObj($i)->getRefID(); ?>')><i class="fa fa-trash"></i></span>
                    <span onclick="getMenuLevelTwo('<?= $menu_all->GetObj($i)->getMenuID(); ?>')"><i class="fa fa-fw fa-calendar"></i> <?= $menu_all->GetObj($i)->getMenuName(); ?></span>
                </a>
                <?php
            }
        }
        break;
    case 4:
        $result = $menuService->deleteMenuLevel1($_POST['menuID']);
        if ($result == 200) {
            $menu_all = $menuService->getAllMenuLevelOneByMainMenuID($_POST['ref_id']);
            for ($i = 0; $i < $menu_all->Size(); $i++) {
                ?>
                <a href="#" class="list-group-item">
                    <span class="badge"><i class="fa fa-code"></i></span>
                    <span class="badge" onclick="editMenuLevel1('<?= $menu_all->GetObj($i)->getMenuID(); ?>', '<?= $menu_all->GetObj($i)->getMenuName(); ?>', '<?= $menu_all->GetObj($i)->getRefID(); ?>')"><i class="fa fa-edit"></i></span>
                    <span class="badge" onclick=deleteMenuLevel1('<?= $menu_all->GetObj($i)->getMenuID(); ?>','<?= $menu_all->GetObj($i)->getRefID(); ?>')><i class="fa fa-trash"></i></span>
                    <span onclick="getMenuLevelTwo('<?= $menu_all->GetObj($i)->getMenuID(); ?>')"><i class="fa fa-fw fa-calendar"></i> <?= $menu_all->GetObj($i)->getMenuName(); ?></span>
                </a>
                <?php
            }
        }
        break;
    case 5:
        $menuTO = new Menu();
        $menuTO->setMenuID($_POST['menuID']);
        $menuTO->setMenuName($_POST['menuName']);
        $menuTO->setRefID($_POST['ref_id']);
        $result = $menuService->updateMenuLevel1($menuTO);
        if ($result == 200) {
            $menu_all = $menuService->getAllMenuLevelOneByMainMenuID($_POST['ref_id']);
            for ($i = 0; $i < $menu_all->Size(); $i++) {
                ?>
                <a href="#" class="list-group-item">
                    <span class="badge" onclick="showContentTable('<?= $menu_all->GetObj($i)->getMenuID(); ?>', '<?= $menu_all->GetObj($i)->getMenuName(); ?>')"><i class="fa fa-code"></i></span>
                    <span class="badge" onclick="editMenuLevel1('<?= $menu_all->GetObj($i)->getMenuID(); ?>', '<?= $menu_all->GetObj($i)->getMenuName(); ?>', '<?= $menu_all->GetObj($i)->getRefID(); ?>')"><i class="fa fa-edit"></i></span>
                    <span class="badge" onclick=deleteMenuLevel1('<?= $menu_all->GetObj($i)->getMenuID(); ?>','<?= $menu_all->GetObj($i)->getRefID(); ?>')><i class="fa fa-trash"></i></span>
                    <span onclick="getMenuLevelTwo('<?= $menu_all->GetObj($i)->getMenuID(); ?>')"><i class="fa fa-fw fa-calendar"></i> <?= $menu_all->GetObj($i)->getMenuName(); ?></span>
                </a>
                <?php
            }
        }
    case 6:
        $menuTO = new Menu();
        $menuTO->setMenuID(uniqid());
        $menuTO->setMenuCreatedDateTime(date('Y-m-d h:i:s', time()));
        $menuTO->setRefID($_POST['ref_id']);
        $menuTO->setMenuName($_POST['menuName']);
        $result = $menuService->createNewMenuLevel2($menuTO);
        if ($result == 200) {
            $menu_all = $menuService->getAllMenuLevelTwoByMainMenuID($_POST['ref_id']);
            for ($i = 0; $i < $menu_all->Size(); $i++) {
                ?>
                <a href="#" class="list-group-item">
                    <span class="badge" onclick="showContentTable('<?= $menu_all->GetObj($i)->getMenuID(); ?>', '<?= $menu_all->GetObj($i)->getMenuName(); ?>')"><i class="fa fa-code"></i></span>
                    <span class="badge" onclick="editMenuLevel3('<?= $menu_all->GetObj($i)->getMenuID(); ?>', '<?= $menu_all->GetObj($i)->getMenuName(); ?>', '<?= $menu_all->GetObj($i)->getRefID(); ?>')"><i class="fa fa-edit"></i></span>
                    <span class="badge" onclick="deleteMenuLevel3('<?= $menu_all->GetObj($i)->getMenuID(); ?>', '<?= $menu_all->GetObj($i)->getRefID(); ?>')"><i class="fa fa-trash"></i></span>
                    <span><i class="fa fa-fw fa-calendar"></i> <?= $menu_all->GetObj($i)->getMenuName(); ?></span>
                </a>
                <?php
            }
        }
        break;
    case 7:
        $result = $menuService->deleteMenuLevel2($_POST['menuID']);
        if ($result == 200) {
            $menu_all = $menuService->getAllMenuLevelTwoByMainMenuID($_POST['ref_id']);
            for ($i = 0; $i < $menu_all->Size(); $i++) {
                ?>
                <a href="#" class="list-group-item">
                    <span class="badge" onclick="showContentTable('<?= $menu_all->GetObj($i)->getMenuID(); ?>', '<?= $menu_all->GetObj($i)->getMenuName(); ?>')"><i class="fa fa-code"></i></span>
                    <span class="badge" onclick="editMenuLevel3('<?= $menu_all->GetObj($i)->getMenuID(); ?>', '<?= $menu_all->GetObj($i)->getMenuName(); ?>', '<?= $menu_all->GetObj($i)->getRefID(); ?>')"><i class="fa fa-edit"></i></span>
                    <span class="badge" onclick="deleteMenuLevel3('<?= $menu_all->GetObj($i)->getMenuID(); ?>', '<?= $menu_all->GetObj($i)->getRefID(); ?>')"><i class="fa fa-trash"></i></span>
                    <span><i class="fa fa-fw fa-calendar"></i> <?= $menu_all->GetObj($i)->getMenuName(); ?></span>
                </a>
                <?php
            }
        }
        break;
    case 8:
        $menuTO = new Menu();
        $menuTO->setMenuID($_POST['menuID']);
        $menuTO->setRefID($_POST['ref_id']);
        $menuTO->setMenuName($_POST['menuName']);
        $result = $menuService->updateMenuLevel2($menuTO);
        if ($result == 200) {
            $menu_all = $menuService->getAllMenuLevelTwoByMainMenuID($_POST['ref_id']);
            for ($i = 0; $i < $menu_all->Size(); $i++) {
                ?>
                <a href="#" class="list-group-item">
                    <span class="badge" onclick="showContentTable('<?= $menu_all->GetObj($i)->getMenuID(); ?>', '<?= $menu_all->GetObj($i)->getMenuName(); ?>')"><i class="fa fa-code"></i></span>
                    <span class="badge" onclick="editMenuLevel3('<?= $menu_all->GetObj($i)->getMenuID(); ?>', '<?= $menu_all->GetObj($i)->getMenuName(); ?>', '<?= $menu_all->GetObj($i)->getRefID(); ?>')"><i class="fa fa-edit"></i></span>
                    <span class="badge" onclick="deleteMenuLevel3('<?= $menu_all->GetObj($i)->getMenuID(); ?>', '<?= $menu_all->GetObj($i)->getRefID(); ?>')"><i class="fa fa-trash"></i></span>
                    <span><i class="fa fa-fw fa-calendar"></i> <?= $menu_all->GetObj($i)->getMenuName(); ?></span>
                </a>
                <?php
            }
        }
        break;
    case 999:
        $menu_all = $menuService->getAllMenuLevelOneByMainMenuID($_POST['mainMenuID']);
        for ($i = 0; $i < $menu_all->Size(); $i++) {
            ?>
            <a href="#" class="list-group-item">
                <span class="badge" onclick="showContentTable('<?= $menu_all->GetObj($i)->getMenuID(); ?>', '<?= $menu_all->GetObj($i)->getMenuName(); ?>')"><i class="fa fa-code"></i></span>
                <span class="badge" onclick="editMenuLevel1('<?= $menu_all->GetObj($i)->getMenuID(); ?>', '<?= $menu_all->GetObj($i)->getMenuName(); ?>', '<?= $menu_all->GetObj($i)->getRefID(); ?>')"><i class="fa fa-edit"></i></span>
                <span class="badge" onclick=deleteMenuLevel1('<?= $menu_all->GetObj($i)->getMenuID(); ?>','<?= $menu_all->GetObj($i)->getRefID(); ?>')><i class="fa fa-trash"></i></span>
                <span onclick="getMenuLevelTwo('<?= $menu_all->GetObj($i)->getMenuID(); ?>')"><i class="fa fa-fw fa-calendar"></i> <?= $menu_all->GetObj($i)->getMenuName(); ?></span>
            </a>
            <?php
        }
        break;
    //Get All Main Menu
    case 99:
        $menu_all = $menuService->getAllMenu();
        for ($i = 0; $i < $menu_all->Size(); $i++) {
            ?>
            <a href="#" class="list-group-item">
                <span class="badge" onclick="editMainMenu('<?= $menu_all->GetObj($i)->getMenuID(); ?>', '<?= $menu_all->GetObj($i)->getMenuName(); ?>')"><i class="fa fa-edit"></i></span>
                <span class="badge" onclick=deleteMainMenu('<?= $menu_all->GetObj($i)->getMenuID(); ?>')><i class="fa fa-trash"></i></span>
                <span onclick="getMenuLevelOne('<?= $menu_all->GetObj($i)->getMenuID(); ?>')"><i class="fa fa-fw fa-calendar"></i> <?= $menu_all->GetObj($i)->getMenuName(); ?></span>
            </a>
            <?php
        }
        break;
    case 9999:
        $menu_all = $menuService->getAllMenuLevelTwoByMainMenuID($_POST['mainMenuID']);
        for ($i = 0; $i < $menu_all->Size(); $i++) {
            ?>
            <a href="#" class="list-group-item">
                <span class="badge" onclick="showContentTable('<?= $menu_all->GetObj($i)->getMenuID(); ?>', '<?= $menu_all->GetObj($i)->getMenuName(); ?>')"><i class="fa fa-code"></i></span>
                <span class="badge" onclick="editMenuLevel3('<?= $menu_all->GetObj($i)->getMenuID(); ?>', '<?= $menu_all->GetObj($i)->getMenuName(); ?>', '<?= $menu_all->GetObj($i)->getRefID(); ?>')"><i class="fa fa-edit"></i></span>
                <span class="badge" onclick="deleteMenuLevel3('<?= $menu_all->GetObj($i)->getMenuID(); ?>', '<?= $menu_all->GetObj($i)->getRefID(); ?>')"><i class="fa fa-trash"></i></span>
                <span><i class="fa fa-fw fa-calendar"></i> <?= $menu_all->GetObj($i)->getMenuName(); ?></span>
            </a>
            <?php
        }
        break;
}